package com.trendata.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trendata.domain.Comment;
import com.trendata.service.CommentService;
import com.trendata.util.JsonResult;

/**
 * 评论的接口
 * 
 * @author: HuangXiuXiu Email:243559392@qq.com
 */
@Controller
@RequestMapping("/comment")
public class CommentController {
	@Autowired
	private CommentService commentService;

	/**
	 * 通过照片id获得评论
	 * <p>
	 * url=/comment/selectCommentsByImageId.do?imageId=图片编号
	 * </p>
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/selectCommentsByImageId")
	@ResponseBody
	public String selectCommentsByImageId(HttpServletRequest request, HttpServletResponse response) {
		JsonResult result = new JsonResult();
		String imageId = request.getParameter("imageId");
		List<Comment> comments = commentService.selectByImageId(Long.valueOf(imageId));
		result.setSuccess(true);
		result.setValue(comments);
		return result.toJsonString();
	}
	
}
